﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SharingCenter.Web.Shared
{
    using WindowsLive;
    using SharingCenter.Web.Classes;
    using System.Web.Security;
    using SharingCenter.Web.Classes.Profiles;
    using SharingCenter.Web.Classes.Account;
    public partial class LiveHandler : PageBase
    {
        static WindowsLiveLogin wll = new WindowsLiveLogin(true);
        protected void Page_Load(object sender, EventArgs e)
        {
            WindowsLiveLogin wll = new WindowsLiveLogin(true);
            WindowsLiveLogin.ConsentToken token = wll.ProcessConsent(Request.Form);
            if (token != null)
            {
                //Guid uid = new Guid(token.Context);
                //string uname = AccountOperations.GetUserName(uid);
                //WebProfile p = WebProfile.GetProfile(uname, true);
                //p.LiveToken = token;
                //p.Save();
                //HttpCookie lid = new HttpCookie("lid", token.LocationID);
                
                Response.Cookies.Add(new HttpCookie("lid", token.LocationID));
                Response.Cookies.Add(new HttpCookie("token", token.DelegationToken));
            }
            Response.Write("<script>this.close();</script>");
        }
    }
}
